import 'package:json_annotation/json_annotation.dart';
import 'package:objectbox/objectbox.dart';

//数据库生成: flutter pub run build_runner build
//定义生成的文件 flutter pub run build_runner build --delete-conflicting-outputs
part 'models_cuxiao.g.dart';

//商品拥有的促销
@JsonSerializable(explicitToJson: true)
@Entity()
class DbCXProduct {
  @Id()
  int id=0;

  bool? excl;//是否为排除选项
  String? planIdEach;//促销id列表 planIds平铺处理
  String? productType;//-1商品/分类0/品牌1/系列2/商品档案属性3/商品规格属性4/清单id5
  String? typeId;//选项id 商品/分类/品牌/系列/商品档案属性/商品规格属性 id  (注意: 商品是规格级别,对应specId,如果是多规格商品,itemId是查不到的)
  String? parentId;//节点id，productType=分类0/品牌1/系列2/商品档案属性3/商品规格属性4 时存在,其他场景为NULL

  int version=0;//数据版本号

  DbCXProduct(
      {
        this.id=0,
        this.version=0,
        this.excl,
        this.planIdEach,
        this.productType,
        this.typeId,
        this.parentId,
      }
      );


  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is DbCXProduct &&
          runtimeType == other.runtimeType &&
          planIdEach == other.planIdEach &&
          productType == other.productType;

  @override
  int get hashCode => planIdEach.hashCode ^ productType.hashCode;

  //添加固定格式
  factory DbCXProduct.fromJson(Map<String, dynamic> json) => _$DbCXProductFromJson(json);
  Map<String, dynamic> toJson() => _$DbCXProductToJson(this);

}

//促销品清单
@JsonSerializable(explicitToJson: true)
@Entity()
class DbCXItemBomProduct {
  @Id()
  int id=0;
  int version=0;//数据版本号

   String? bomId; //清单id
   String? itemId;//商品id
   String? specId;//规格id

   String? giftMustQty; //必须数量
   String? giftMustSel;

  DbCXItemBomProduct(
      {
        this.id=0,
        this.version=0,
        this.bomId,
        this.itemId,
        this.specId,
        this.giftMustQty,
        this.giftMustSel,
      }
      );


  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is DbCXItemBomProduct &&
          runtimeType == other.runtimeType &&
          bomId == other.bomId &&
          itemId == other.itemId &&
          specId == other.specId;

  @override
  int get hashCode => bomId.hashCode ^ itemId.hashCode ^ specId.hashCode;

  //添加固定格式
  factory DbCXItemBomProduct.fromJson(Map<String, dynamic> json) => _$DbCXItemBomProductFromJson(json);
  Map<String, dynamic> toJson() => _$DbCXItemBomProductToJson(this);

}

//固定,组合套餐
@JsonSerializable(explicitToJson: true)
@Entity()
class DbCXSuitBom {
  @Id()
  int id=0;
   String? bomId;//
   String? planId;

   int version=0;//数据版本号


  DbCXSuitBom(
      {
        this.id=0, this.version=0, this.bomId, this.planId,
      });


  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is DbCXSuitBom &&
          runtimeType == other.runtimeType &&
          bomId == other.bomId &&
          planId == other.planId;

  @override
  int get hashCode => bomId.hashCode ^ planId.hashCode;

  //添加固定格式
  factory DbCXSuitBom.fromJson(Map<String, dynamic> json) => _$DbCXSuitBomFromJson(json);
  Map<String, dynamic> toJson() => _$DbCXSuitBomToJson(this);

}

//促销
@JsonSerializable(explicitToJson: true)
@Entity()
class DbCXPromotion {
  @Id()
  int id=0;
  int version=0;//数据版本号

   String? planId;//促销规则id
   String? planType;//促销规则类型 P001(“单品促销”),P002(“订单促销”),P003(“组合促销”),P004(“套餐促销”),P005(“指定特价”);
   String? beginDate;
   String? endDate;
   String? startTime;
   String? endTime;
   String? projectId;//方案id
   String? promotionJson; //促销json


  DbCXPromotion({this.id=0, this.version=0,
    this.planId,
    this.planType,
    this.beginDate,
    this.endDate,
    this.startTime,
    this.endTime,
    this.projectId,
    this.promotionJson,
  });

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is DbCXPromotion &&
          runtimeType == other.runtimeType &&
          planId == other.planId &&
          planType == other.planType &&
          projectId == other.projectId;

  @override
  int get hashCode => planId.hashCode ^ planType.hashCode ^ projectId.hashCode;

  //添加固定格式
  factory DbCXPromotion.fromJson(Map<String, dynamic> json) => _$DbCXPromotionFromJson(json);
  Map<String, dynamic> toJson() => _$DbCXPromotionToJson(this);

}


//秒杀商品
@JsonSerializable(explicitToJson: true)
@Entity()
class DbCXItemTimed {
  @Id()
  int id=0;
  int version=0;//数据版本号

   String? planId;//促销规则id

   String? itemId;
   String? specId;

   String? leftLimitNumPerDay; //每天限购总数
   String? leftTotalLimitNum; //限购总数-剩余数量
   String? limitNumPerDay;//每天限购总数-剩余
   String? limitPurchases;//每单限购数量
   String? specialPrice;//指定价格
   String? totalLimitNum;//限购总数


  DbCXItemTimed({this.id=0, this.version=0,
    this.planId,
    this.itemId,
    this.specId,
    this.leftLimitNumPerDay,
    this.leftTotalLimitNum,
    this.limitNumPerDay,
    this.limitPurchases,
    this.specialPrice,
    this.totalLimitNum,
  });


  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is DbCXItemTimed &&
          runtimeType == other.runtimeType &&
          planId == other.planId &&
          itemId == other.itemId &&
          specId == other.specId;

  @override
  int get hashCode => planId.hashCode ^ itemId.hashCode ^ specId.hashCode;

  //添加固定格式
  factory DbCXItemTimed.fromJson(Map<String, dynamic> json) => _$DbCXItemTimedFromJson(json);
  Map<String, dynamic> toJson() => _$DbCXItemTimedToJson(this);

}

/*
a、openMutex 开启促销互斥
b、mutexType互斥类型 0指定规则 1所有规则
前端遇到openMutex = true,mutexType=0 时去请求 客户端提供的互斥促销列表。
如果openMutex = true,mutexType= 1，跟所有促销互斥
 */
@JsonSerializable(explicitToJson: true)
@Entity()
class DbCXMutexPlan {
  @Id()
  int id=0;
  int version=0;//数据版本号

   String? mutexPlanId;//
   String? planId;


  DbCXMutexPlan({this.id=0, this.version=0,
    this.planId,
    this.mutexPlanId,
  });


  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is DbCXMutexPlan &&
          runtimeType == other.runtimeType &&
          mutexPlanId == other.mutexPlanId &&
          planId == other.planId;

  @override
  int get hashCode => mutexPlanId.hashCode ^ planId.hashCode;

  //添加固定格式
  factory DbCXMutexPlan.fromJson(Map<String, dynamic> json) => _$DbCXMutexPlanFromJson(json);
  Map<String, dynamic> toJson() => _$DbCXMutexPlanToJson(this);

}
//订单所拥有的促销
@JsonSerializable(explicitToJson: true)
@Entity()
class DBCXOrderProduct {
  @Id()
  int id=0;
  int version=0;//数据版本号

   bool? excl;//是否为排除选项
   String? planId; //促销id
   String? productType; //-1商品/分类0/品牌1/系列2/商品档案属性3/商品规格属性4/清单id5
   String? typeId;//选项id 商品/分类/品牌/系列/商品档案属性/商品规格属性 id
   String? parentId;//节点id，productType=分类0/品牌1/系列2/商品档案属性3/商品规格属性4 时存在,其他场景为NULL


  DBCXOrderProduct({this.id=0, this.version=0,
    this.planId,
    this.excl,
    this.productType,
    this.typeId,
    this.parentId,
  });


  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is DBCXOrderProduct &&
          runtimeType == other.runtimeType &&
          planId == other.planId &&
          productType == other.productType &&
          typeId == other.typeId;

  @override
  int get hashCode => planId.hashCode ^ productType.hashCode ^ typeId.hashCode;

  //添加固定格式
  factory DBCXOrderProduct.fromJson(Map<String, dynamic> json) => _$DBCXOrderProductFromJson(json);
  Map<String, dynamic> toJson() => _$DBCXOrderProductToJson(this);

}


